﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Threading;

using Factonomy.AzureUtility.Core;
using Factonomy.AzureUtility.Core.Storage;
using Factonomy.AzureUtility.Core.StorageHelpers;

namespace Factonomy.AzureUtility.Dialogs
{
    /// <summary>
    /// Interaction logic for ImageViewer.xaml
    /// </summary>
    public partial class ImageViewer : Window
    {
        private BlobProperties _properties = null;

        public ImageViewer()
        {
            InitializeComponent();
        }

        public void Load(BlobProperties properties)
        {
            this._properties = properties;
            this.Cursor = Cursors.Wait;
            this.uiStatusText.Text = "Downloading image...";
            this.DownloadImage(true);
        }

        private void DownloadImage(object startThread)
        {
            BitmapImage bitmapImage = new BitmapImage();
            bitmapImage.DownloadCompleted += new EventHandler(myBitmapImage_DownloadCompleted);
            bitmapImage.BeginInit();
            bitmapImage.UriSource = this._properties.Uri;
            bitmapImage.EndInit();
        }

        void myBitmapImage_DownloadCompleted(object sender, EventArgs e)
        {
            uiImageMain.Source = sender as BitmapImage;
            this.Width = uiImageMain.Source.Width;
            this.Height = uiImageMain.Source.Height;
            this.uiStatusText.Text = "Ready";
            this.Cursor = Cursors.Arrow;
        }

    }
}
